﻿using SuperFx;
using SuperMoney.Datas;
using SuperMoney.Datas.DbModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperMoney
{
	/// <summary>
	/// 广告记录服务。
	/// </summary>
	public class AdRecordService
	{
		/// <summary>
		/// 广告记录服务实例。
		/// </summary>
		public static AdRecordService Instance = new AdRecordService();

		/// <summary>
		/// 创建广告记录。
		/// </summary>
		/// <param name="adPlatform"></param>
		/// <param name="adOrderId"></param>
		/// <param name="adOrderTime"></param>
		/// <param name="adEffectTime"></param>
		/// <param name="adDeviceId"></param>
		/// <param name="adId"></param>
		/// <param name="adName"></param>
		/// <param name="adChannel"></param>
		/// <param name="integral"></param>
		/// <param name="appIncome"></param>
		/// <param name="appKey"></param>
		/// <param name="device"></param>
		/// <param name="deviceId"></param>
		public void Create(string adPlatform, string adOrderId, DateTime? adOrderTime, int adEffectTime, string adDeviceId, string adId, string adName, string adChannel, int integral, decimal appIncome, string appKey, string device, string deviceId)
		{
			if (AdRecordDbService.Instance.Exists(adPlatform, adOrderId))
			{
				throw new Exception<AdRecordExistsExceptionArgs>(new AdRecordExistsExceptionArgs());
			}

			AdRecord adRecord = new AdRecord();
			adRecord.AdPlatform = adPlatform;
			adRecord.AdOrderId = adOrderId;
			adRecord.AdOrderTime = adOrderTime;
			adRecord.AdEffectTime = adEffectTime;
			adRecord.AdDeviceId = adDeviceId;
			adRecord.AdId = adId;
			adRecord.AdName = adName;
			adRecord.AdChannel = adChannel;
			adRecord.Integral = integral;
			adRecord.AppIncome = appIncome;
			adRecord.AppKey = appKey;
			adRecord.Device = device;
			adRecord.DeviceId = deviceId;
			AdRecordDbService.Instance.Create(adRecord);

			IntegralTradeService.Instance.Create(deviceId, IntegralTradeCategory.Income, integral, adName, IntegralTradeAssociation.AdRecord, adRecord.Id);
		}
	}
}
